package com.itheima.service.impl;

import com.itheima.mapper.ReportMapper;
import com.itheima.service.ReportService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@DubboService
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;

    @Override
    public Map totalMemberCounts() {
        List<Map> mapList =  reportMapper.totalMemberCounts();
        return  changeMapListTOMap(mapList);
    }

    @Override
    public List<Map> orderSetmealProportion() {

       return reportMapper.orderSetmealProportion();
    }

    @Override
    public Map getMemberCountsByMonth(String startMonth,String endMonth) {
        List<Map> mapList = reportMapper.getMemberCountsByMonth(startMonth, endMonth);
        return changeMapListTOMap(mapList);
    }

    @Override
    public List<Map> memberSexProportion() {
        return reportMapper.memberSexProportion();
    }

    @Override
    public Integer todayNewMember() {
        return reportMapper.todayNewMember();
    }

    @Override
    public Integer thisWeekNewMember() {
        return reportMapper.thisWeekNewMember();
    }

    @Override
    public Integer totalMember() {

        return reportMapper.totalMember();
    }

    @Override
    public Integer thisMonthNewMember() {

        return reportMapper.thisMonthNewMember();
    }

    @Override
    public Integer todayOrderNumber() {
        return reportMapper.todayOrderNumber();
    }

    @Override
    public Integer todayVisitsNumber() {
        return reportMapper.todayVisitsNumber();
    }

    @Override
    public Integer thisWeekOrderNumber() {
        return reportMapper.thisWeekOrderNumber();
    }

    @Override
    public Integer thisWeekVisitsNumber() {
        return reportMapper.thisWeekVisitsNumber();
    }

    @Override
    public Integer thisMonthOrderNumber() {
        return reportMapper.thisMonthOrderNumber();
    }

    @Override
    public Integer thisMonthVisitsNumber() {
        return reportMapper.thisMonthVisitsNumber();
    }

    @Override
    public List<Map<String, String>> hotSetmeal() {
        return reportMapper.hotSetmeal();
    }

    @Override
    public List<Map> memberAgeProportion() {
        return reportMapper.memberAgeProportion();
    }

    private Map changeMapListTOMap(List<Map> mapList) {
        Map  map = new HashMap();
        List<String> yearAndMonths = new ArrayList<>();
        List<Long> memberCounts = new ArrayList<>();
        for (Map map1 : mapList) {
            memberCounts.add((Long)map1.get("totalCounts"));
            yearAndMonths.add((String)map1.get("yearAndMonth"));
        }
        map.put("yearAndMonths",yearAndMonths);
        map.put("totalCounts",memberCounts);
        return  map;
    }



}
